package Weapon;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import Map.EnumTile;

public class PathAIDetail {
	Map<List<Point>, Integer> bullets;

	public PathAIDetail(Map<List<Point>, Integer> _bullets) {
		bullets = _bullets;
		new Thread() {
			public void run() {
				while (true) {

					try {
						Thread.sleep(50);
					} catch (Exception e) {

					}
					for (List<Point> points : bullets.keySet()) {
						bullets.put(points, bullets.get(points) + 1);
					}
					List<List<Point>> removeLists = new ArrayList<List<Point>>();
					for (List<Point> points : bullets.keySet()) {
						if (points.size() - 1 == bullets.get(points))
							removeLists.add(points);
					}
					for (List<Point> removeList : removeLists)
						bullets.remove(removeList);

				}

			}
		}.start();
	}

	public void addPath(int selfx, int selfy, int targetx, int targety) {
//		List<Point> m = new ArrayList<Point>();
//		m.add(new )
//		bullets.put(findLine(selfx, selfy, targetx, targety), 0);

	}

	public List<Point> findLine(int x0, int y0, int x1, int y1)

	{
		List<Point> points = new ArrayList<Point>();
		int dx = Math.abs(x1 - x0);
		int dy = Math.abs(y1 - y0);
		int sx = x0 < x1 ? 1 : -1;
		int sy = y0 < y1 ? 1 : -1;
		int err = dx - dy;
		int e2;
		while (true) {


			points.add(new Point(x0, y0));
			if (x0 == x1 && y0 == y1)
				break;

			e2 = 2 * err;
			if (e2 > -dy) {
				err = err - dy;
				x0 = x0 + sx;
			}
			if (e2 < dx) {
				err = err + dx;
				y0 = y0 + sy;
			}
		}
		return points;

	}
}
